// 引入外链html文件的一版
// 把外链html的内容读取后响应即可

const http = require('http');
const fs = require('fs');
const path = require('path');
const server = http.createServer();
server.on('request', (req, res) => {
  if (req.url === '/' || req.url === '/index.html') {
    // 读取内容
    fs.readFile(path.join(__dirname, './html/index.html'), 'utf8', (err, data) => {
      if (err) return err;
      res.end(data);
    })
  } else if (req.url === '/son.html') {
    fs.readFile(path.join(__dirname, './html/son.html'), 'utf8', (err, data) => {
      if (err) return err;
      res.end(data);
    })
  } else if (req.url === '/brother.html') {
    fs.readFile(path.join(__dirname, './html/brother.html'), 'utf8', (err, data) => {
      if (err) return err;
      res.end(data);
    })
  } else {
    res.writeHead(200, {
      "Content-Type": "text/html;charset=UTF-8"
    })
    res.end('页面找不到，呀哈');
  }
})
server.listen(8899, () => {
  console.log('http://127.0.0.1:8899');
})